<template>
  <a-form ref="dictionaryFormRef" :model="dictionaryModel" :rules="dictionaryFormRule" v-bind="layout">
    <a-form-item name="codeItemId" :label="t('org.dictionary-type.typeCode')">
      <a-input v-model:value="dictionaryModel.codeItemId" :disabled="true" />
    </a-form-item>
    <a-form-item name="codeId" :label="t('org.dictionary.dictionaryCode')">
      <a-input v-model:value="dictionaryModel.codeId" :placeholder="t('org.dictionary.formPlhCodeId')" />
    </a-form-item>

    <a-form-item name="codeName" :label="t('org.dictionary.dictionaryName')">
      <a-input v-model:value="dictionaryModel.codeName" :placeholder="t('org.dictionary.formPlhCodeName')" />
    </a-form-item>

    <a-form-item name="sortNo" :label="t('org.dictionary.sort')">
      <a-input-number
        :min="1"
        :max="9999999"
        style="width: 100%"
        :placeholder="t('org.dictionary.formPlhSortNo')"
        v-model:value="dictionaryModel.sortNo"
      />
    </a-form-item>
  </a-form>
</template>
<script lang='ts'>
import { defineComponent, ref } from 'vue'
import dictionaryApi from '/@/api/org/dictionary'
import { dictionaryFormRule } from '../interface'
import { useModelForm } from '/@/kit/model-kit'
import { useI18n } from 'vue-i18n'
export default defineComponent({
  props: {
    dictionaryId: String,
    codeItemId: String,
  },
  setup(props, { emit }) {
    const { t } = useI18n()
    const dictionaryFormRef = ref()
    const dictionaryModel = ref({ codeItemId: null })
    const { save } = useModelForm(dictionaryFormRef, dictionaryModel, props.dictionaryId, dictionaryApi, {
      initAddAfter: () => {
        dictionaryModel.value.codeItemId = props.codeItemId
      },
    })
    //提交方法
    const onSubmit = () => save().then((res) => emit('submitSuccess', res.data.data))
    //布局
    const layout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 15 },
    }
    return {
      t,
      dictionaryFormRef,
      dictionaryModel,
      dictionaryFormRule,
      layout,
      onSubmit,
    }
  },
})
</script>